package com.example.springtask.serializer;

import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import org.springframework.core.serializer.Serializer;
import org.springframework.kafka.support.serializer.JsonSerializer;

import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class CustomerSerializer implements org.apache.kafka.common.serialization.Serializer<Object> {

    @Override
    public byte[] serialize(String topic, Object obj) {
        try(ByteOutputStream bos = new ByteOutputStream()){
            ObjectOutput objectOutput = new ObjectOutputStream(bos);
            objectOutput.writeObject(obj);
            return bos.getBytes();
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
